package Envo 
{
	import flash.display.MovieClip;
	import com.as3toolkit.events.KeyboarderEvent;
	import com.as3toolkit.ui.Keyboarder;
	
	/**
	 * @author Sam Morrison
	 */
	public class Player extends MovieClip 
	{
		// Physics varibles
		public var verticalVelocity:Number = 0;			// Current horizontal acceleration
		public var verticalAcceleration:Number = 0;		// Current horizontal acceleration
		
		public var horizontalVelocity:Number = 0;		// Current horizontal acceleration
		public var horizontalAcceleration:Number = 0;	// Current horizontal acceleration
		
		public var currentJumps:int;					// Current amount of jumps left
		
		// Attributes
		public var movingLeft:Boolean;					// Moving left button
		public var movingRight:Boolean;					// Moving right button
		
		public var jumping:Boolean;						// Jumping button
		public var jumpReleased:Boolean = true;			// Jumping button has released
		
		public var previousX:Number = 360;				// Previous X location - initial settings center the camera
		public var previousY:Number = 240;				// Previous Y location - initial settings center the camera
		
		public var mc_boundingBox:MovieClip;			// Player's bounding box
		
		public var collidingVertical:String;			// Player collisions with wall
		public var collidingHorizontal:String;			// Player collisions with wall
		
		public var facing:String;						// Player's facing
		
		public function Player() 
		{
			// Initialize key release listener
			Keyboarder.Instance.addEventListener(KeyboarderEvent.RELEASE, keyRelease);
		}
		
		// Checks keyboard for input
		public function update():void
		{
			//Moving Left
			if (Keyboarder.keyIsDown(65) || Keyboarder.keyIsDown(37))
			{
				movingLeft = true;
				facing = "left";
			}
			else
			{
				movingLeft = false;
			}
			
			
			//Moving Right
			if (Keyboarder.keyIsDown(68) || Keyboarder.keyIsDown(39))
			{
				movingRight = true;
				facing = "right";
			}
			else
			{
				movingRight = false;
			}
			
			//Jumping
			if (Keyboarder.keyIsDown(87) || Keyboarder.keyIsDown(38))
			{
				jumping = true;
			}
			else
			{
				jumping = false;
			}
		}
		
		// Checks if the jumping key released
		public function keyRelease(e:KeyboarderEvent):void
		{
			if (e.keyCode == 87 || e.keyCode == 38)
			{
				jumpReleased = true;
			}
		}
		
	}

}